//
//  MSSecurityViewController.m
//  MSJD
//
//  Created by 箭军刘 on 2018/12/2.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSSecurityViewController.h"

#import "MSResetPswController.h"

#import "MSUserCenterCell.h"

/** 安全设置界面的类型 */
typedef NS_ENUM(NSInteger, MSSecurityCellType) {
    MSSecurityCellTypeAccount = 0, // 登录账号
    MSSecurityCellTypeModifyPassword, // 修改密码
    MSSecurityCellTypeBindPhone // 绑定手机
};

@interface MSSecurityViewController ()

@end

@implementation MSSecurityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"安全设置";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MSUserCenterCell" bundle:nil] forCellReuseIdentifier:@"MSUserCenterCell"];
    
    self.customDataSource = @[@"登录账号", @"修改密码", @"绑定手机"];
    [self.tableView reloadData];
}

#pragma mark - Reset Method

- (UITableViewCell *)loadCustomCellWithTableView:(UITableView *)tableView Index:(NSIndexPath *)indexPath {
    MSUserCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MSUserCenterCell"];
    
    if (indexPath.row < self.customDataSource.count) {
        NSString *title = self.customDataSource[indexPath.row];
        NSString *rightValue = nil;
        if (indexPath.row == MSSecurityCellTypeAccount) {
            rightValue = @"123456789";
        } else if (indexPath.row == MSSecurityCellTypeBindPhone) {
            // 根据是否有绑定手机而区分展示样式
            if (![MSSafeObject isNull:[UserAccesser loadAccount].phone]) {
                title = @"换绑手机";
            }
        }
        [cell refreshSecurityCellWithTitle:title rightValue:rightValue];
    }
    return cell;
}

- (void)didSelectTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case MSSecurityCellTypeBindPhone:
        { // 绑定手机
            [self presentToBindPhoneVC];
        }
            break;
        case MSSecurityCellTypeModifyPassword:
        { // 修改密码
            [self presentToModifyPasswordVC];
        }
        default:
            break;
    }
}


#pragma mark - Private Method
/** 跳转到修改密码界面 */
- (void)presentToModifyPasswordVC {
    MSResetPswController *modifyVC = [MSResetPswController loadResetPswControllerWithType:MSResetPswTypeModify fromVC:MSResetPwsFromVCTypeSetting];
    [self.navigationController pushViewController:modifyVC animated:YES];
}
/** 跳转到绑定手机界面 */
- (void)presentToBindPhoneVC {
    MSResetPswController *bindPhoneVC = [MSResetPswController loadResetPswControllerWithType:MSResetPswTypeBindPhone fromVC:MSResetPwsFromVCTypeSetting];
    [self.navigationController pushViewController:bindPhoneVC animated:YES];
}

@end
